var rootPath = '';//kk.getRootPath();

/* status of book */
function status(id, index, statusFlag) {
	var url = rootPath + '/Borrow/Borrow/setStatus?id=' + id + '&status=' + statusFlag;
	
	var msg;
	if (statusFlag == 1) {
		msg = '请再次向读者确认，要借阅本书？';
	} else if (statusFlag == 2) {
		msg = '请再次向读者确认，要还回本书？';
	} else if (statusFlag == 3) {
		msg = '请再次向读者确认，要取消本次借阅？';
	}
	
	xpopup.confirm({
    	title: '确认',
        msg: msg,
        buttons: [{
            text: '确认',
            'class': 'btn btn-info',
            handler: function ($this) {
                var xloading = xpopup.loading();
                
    			$.ajax({
    				type: 'PUT',
    				url : url,
    				dataType: 'json',
    				async : false,
    				success: function(data) {
    		        	xloading.destroy();

    					if (data.code == 0) {
    	                	xpopup.notify({
    	    		           	style: 'mini',
    	                    	type: 'success',
    	                    	title: '处理成功',
    	                        msg: data.msg,
    	                        delay: 1000,
    	    					position: 'center',
    	                    });

    	                	if (statusFlag != 3) {
        	                	$('#table').bootstrapTable('updateRow', {
        	        	    		index: index,
        	        				row: data.obj
        	        	    	});	
    	                	} else {
    	                		$('#table').bootstrapTable('refresh');								// refresh
    	                	}
    					} else {
            				kk.extOnLoadSuccess(data);//_________________________________________----------------------------------
    					}
    				},
    				error: kk.extError
    			});
        		$this.destroy();
            }
        }, {
            text: '取消',
            'class': 'btn btn-default',
            handler: function ($this) {
        		$this.destroy();
            }
        }]
    });
}

/* CRUD 1: Create, 2: Read, 3: Update, 4: Delete */
var CREATE = 1, READ = 2, UPDATE = 3, DELETE = 4;
function CRUDBorrowFunc(operCode, id, index) {
	var url = kk.getRootPath() + '/api/borrows/' + id + '.json';
	kk.deleteObj(url, '#table');
}